package com.example.devsa_platform.pojo.doc;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.csv.CSVRecord;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;

import java.io.Serializable;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@Document(indexName = "dev_vocational",createIndex = false)
public class VocationalDoc implements Serializable {
    @Field(name = "ed_level")
    private String edLevel;
    @Field(name = "learn_code")
    private String learnCode;
    @Field(name = "learn_code_online")
    private String learnCodeOnline;
    @Field(name = "learn_code_courses_cert")
    private String learnCodeCoursesCert;
    @Field(name = "years_code")
    private String yearsCode;
    @Field(name = "years_code_pro")
    private String yearsCodePro;
    @Field(name = "dev_type")
    private String devType;
    @Field(name = "org_size")
    private String orgSize;
    @Field(name = "purchase_influence")
    private String purchaseInfluence;
    @Field(name = "tech_list")
    private String techList;
    @Field(name = "buy_new_tool")
    private String buyNewTool;
    @Field(name = "country")
    private String country;
    @Field(name = "currency")
    private String currency;
    @Field(name = "comp_total")
    private String compTotal;

    public VocationalDoc(CSVRecord record){
        this.edLevel = getValueOrDefault(record.get("EdLevel"));
        this.learnCode = getValueOrDefault(record.get("LearnCode"));
        this.learnCodeOnline = getValueOrDefault(record.get("LearnCodeOnline"));
        this.learnCodeCoursesCert = getValueOrDefault(record.get("LearnCodeCoursesCert"));
        this.yearsCode = getValueOrDefault(record.get("YearsCode"));
        this.yearsCodePro = getValueOrDefault(record.get("YearsCodePro"));
        this.devType = getValueOrDefault(record.get("DevType"));
        this.orgSize = getValueOrDefault(record.get("OrgSize"));
        this.purchaseInfluence = getValueOrDefault(record.get("PurchaseInfluence"));
        this.techList = getValueOrDefault(record.get("TechList"));
        this.buyNewTool = getValueOrDefault(record.get("BuyNewTool"));
        this.country = getValueOrDefault(record.get("Country"));
        this.currency = getValueOrDefault(record.get("Currency"));
        this.compTotal = getValueOrDefault(record.get("CompTotal"));
    }

    private String getValueOrDefault(String value) {
        return Objects.equals(value, "NA") ? "No Answer" : value;
    }
}
